package com.my.mvpdemo.mvp1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.my.mvpdemo.Girl;
import com.my.mvpdemo.R;

import java.util.List;

/**
 * Created by 张英杰 on 2017/2/22.
 */

public class GirlAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<Girl>mList;

    public GirlAdapter(Context context, List<Girl> mList) {
        this.inflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList!=null?mList.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       View mview=inflater.inflate(R.layout.adapter_girl_item,null);
        ImageView iv= (ImageView) mview.findViewById(R.id.iv);
        Glide.with(viewGroup.getContext())
                .load(mList.get(i).getImgUrl())
                .placeholder(R.mipmap.ic_launcher)
                .into(iv);
        TextView tv= (TextView) mview.findViewById(R.id.tv);
        tv.setText(mList.get(i).getExplain());
        return mview;
    }
}
